package 作业.大地主;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class test {

    public static void main(String[] args) {
        //1.制作一副扑克牌
        List<Card>allCards=new ArrayList<>();
        String[] colors={"♠","♥","♣","♦"};
        String[] points={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};

        int size=0;
        for(String point:points) {//遍历点数
            size++;
            for(String color:colors) {//遍历花色
                Card card=new Card(color,point,size);
                allCards.add(card);
            }
        }
        System.out.println("制作完成"+allCards);
//大小王
        allCards.add(new Card("🃏","小王",14));
        allCards.add(new Card("😁","大王",15));

//2.洗牌
        Collections.shuffle(allCards);
        System.out.println("洗牌完成"+allCards);
//3.发牌
        List<Card>player1=new ArrayList<>();
        List<Card>player2=new ArrayList<>();
        List<Card>player3=new ArrayList<>();
        List<Card>dipai=new ArrayList<>();
        for (int i = 0; i < allCards.size() - 3; i++) {
            if (i%3 == 0) {
                player1.add(allCards.get(i));
            } else if (i%3 == 1) {
                player2.add(allCards.get(i));
            }else {
                player3.add(allCards.get(i));
            }
        }
        dipai =allCards.subList(allCards.size()-3,allCards.size());


//4.看牌
        System.out.println("玩家1的牌"+player1);
        System.out.println("玩家2的牌"+player2);
        System.out.println("玩家3的牌"+player3);
        System.out.println("底牌"+allCards.subList(allCards.size()-3,allCards.size()));


// 4.5（理牌）
        Collections.sort(player1,(o1,o2)->o1.getSize()-o2.getSize());
        Collections.sort(player2,(o1,o2)->o1.getSize()-o2.getSize());
        Collections.sort(player3,(o1,o2)->o1.getSize()-o2.getSize());

        System.out.println("---------马牌--------");
        System.out.println("玩家1的牌"+player1);
        System.out.println("玩家2的牌"+player2);
        System.out.println("玩家3的牌"+player3);
        System.out.println("底牌"+allCards.subList(allCards.size()-3,allCards.size()));
//5.抢地主
        player1.addAll(dipai);

        //6.地主拿底牌+理牌
        Collections.sort(player1,(o1,o2)->o1.getSize()-o2.getSize());
        System.out.println("玩家1的牌"+player1);
        System.out.println("玩家2的牌"+player2);
        System.out.println("玩家3的牌"+player3);
        System.out.println("底牌"+allCards.subList(allCards.size()-3,allCards.size()));

    }
}
